package com.zyf.school.manager.dao;

import com.zyf.school.manager.domain.Dict;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component("dictDao")
public interface DictDao {
    //保存数据
    @Insert("insert into dict(cord,name,type,parentid) values(#{cord},#{name},#{type},#{parentid})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    public void insert(Dict dict);

    //通过ID查询一个数据
    @Select("select * from dict where id = #{id}")
    public Dict queryById(int id);

    //通过父类id查询子类信息
    @Select("select * from dict where parentid = #{parentid} limit #{startIndex},#{pageSize}")
    public List<Dict> queryByParentId(@Param("parentid") int parentid, @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);

    @Select("select count(*) from dict")
    public int count();

    @Select("select * from dict where parentid=#{parentid}")
    public List<Dict> queryAllById(@Param("parentid") int parentid);

    //删除信息
    @Delete("delete from dict where id = #{id}")
    public void deleteById(int id);

    //更新数据
    @Update("update dict set cord=#{cord},name=#{name},type=#{type},parentid=#{parentid} where id =#{id}")
    public void update();

    //通过类型类来查询
    @Select("select * from dict where type like '%#{type}%' limit #{startIndex},#{pageSize}")
    public List<Dict> queryByType(String type, @Param("startIndex") int startIndex, @Param("pageSize") int pageSize);

    //查询顶级
    @Select("select * from dict where parentid =0 limit #{startIndex},#{pageSize}")
    public List<Dict> queryAllParent(@Param("startIndex") int startIndex, @Param("pageSize") int pageSize);

    @Select("select * from dict limit #{startIndex},#{pageSize}")
    public List<Dict> queryAll(@Param("startIndex") int startIndex, @Param("pageSize") int pageSize);
}
